package ThreadPool.jike.demo14;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @param
 * @author oyz
 * @version 1.1.0
 * @description: TODO
 * @date 2022-8-25 10:20
 */
public class ReentrantLockTest {

    private final Lock lock = new ReentrantLock();
    int value;


    public int get() {
        lock.lock();
        try{
            return value;
        }finally {
            lock.unlock();
        }
    }

    public void addOne(){
        lock.lock();
        try{
            value = 1 + get();
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        ReentrantLockTest reentrantLockTest = new ReentrantLockTest();
        reentrantLockTest.addOne();
        System.out.println(reentrantLockTest.value);
    }
}
